<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Best Image API - 文档</title>
    <!-- 引入Vue 3 -->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <!-- 引入粒子效果 -->
    <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
    <!-- 引入动画库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
    <!-- 引入图标库 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/remixicon@3.5.0/fonts/remixicon.css">
    <style>
        :root {
            --bg: #0a0a0a;
            --neon-blue: #0ff;
            --neon-purple: #9c2aff;
            --neon-pink: #ff36f0;
            --text: #fff;
            --card-bg: rgba(25, 25, 25, 0.85);
            --card-hover-bg: rgba(35, 35, 35, 0.9);
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --primary: #3a86ff;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        body {
            background: var(--bg);
            color: var(--text);
            min-height: 100vh;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 2rem;
        }

        /* 导航栏 */
        .navbar {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(10px);
            z-index: 1000;
            box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        }

        .navbar-brand {
            font-size: 1.5rem;
            font-weight: bold;
            color: var(--neon-blue);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .navbar-links {
            display: flex;
            gap: 1.5rem;
        }

        .navbar-link {
            color: var(--text);
            text-decoration: none;
            position: relative;
            padding: 0.5rem 0;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .navbar-link:hover {
            color: var(--neon-purple);
        }

        .navbar-link::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 0;
            height: 2px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            transition: width 0.3s ease;
        }

        .navbar-link:hover::after {
            width: 100%;
        }

        /* 粒子背景 */
        #particles {
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: -1;
        }

        /* 卡片样式 */
        .card {
            background: var(--card-bg);
            padding: 2rem;
            border-radius: 15px;
            margin: 2rem 0;
            box-shadow: 0 0 20px rgba(156, 42, 255, 0.3);
            transition: all 0.3s ease;
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .card:hover {
            transform: translateY(-5px);
            background: var(--card-hover-bg);
            box-shadow: 0 10px 30px rgba(156, 42, 255, 0.4);
        }

        /* 代码高亮 */
        pre {
            background: #1e1e1e;
            padding: 1.5rem;
            border-radius: 8px;
            overflow-x: auto;
            margin: 1rem 0;
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        code {
            color: var(--neon-blue);
            font-family: 'Fira Code', monospace;
            font-size: 0.95rem;
        }

        /* 动态标题 */
        .title {
            font-size: 3rem;
            text-align: center;
            margin: 2rem 0;
            position: relative;
            text-transform: uppercase;
            letter-spacing: 2px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple), var(--neon-pink));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-size: 200% auto;
            animation: textShine 3s ease-in-out infinite alternate;
        }

        @keyframes textShine {
            0% {
                background-position: 0% center;
            }
            100% {
                background-position: 100% center;
            }
        }

        .title::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            width: 100px;
            height: 3px;
            background: linear-gradient(90deg, var(--neon-blue), var(--neon-purple));
            transform: translateX(-50%);
        }

        /* 参数表格 */
        .params-table {
            width: 100%;
            border-collapse: collapse;
            margin: 2rem 0;
        }

        .params-table td {
            padding: 1rem;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }

        .params-table td:first-child {
            width: 30%;
            color: var(--neon-purple);
        }

        /* 可复制代码框样式 */
        .code-copy {
            position: relative;
            display: block;
            margin: 1rem 0;
            width: 100%;
        }
        
        .code-copy pre {
            display: block;
            padding-right: 60px; /* 为按钮留出空间 */
            width: 100%;
        }
        
        .copy-btn {
            position: absolute;
            right: 10px;
            top: 10px;
            background: var(--neon-purple);
            color: white;
            border: none;
            border-radius: 4px;
            padding: 0.5rem 1rem;
            cursor: pointer;
            font-family: inherit;
            font-size: 0.9rem;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .copy-btn:hover {
            background: #8a2be2;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(138, 43, 226, 0.4);
        }

        .copy-btn:active {
            transform: translateY(0);
        }

        /* 功能列表样式 */
        .feature-list {
            list-style: none;
            padding: 0;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 1rem;
            margin: 1.5rem 0;
        }

        .feature-item {
            background: rgba(40, 40, 40, 0.6);
            padding: 1.2rem;
            border-radius: 10px;
            display: flex;
            align-items: center;
            gap: 0.8rem;
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .feature-item:hover {
            transform: translateY(-3px);
            background: rgba(50, 50, 50, 0.7);
            box-shadow: 0 7px 20px rgba(0, 0, 0, 0.2);
            border-color: rgba(156, 42, 255, 0.3);
        }

        .feature-icon {
            font-size: 1.5rem;
            color: var(--neon-purple);
        }

        /* 按钮样式 */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.7rem 1.5rem;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(58, 134, 255, 0.4);
        }

        .btn:active {
            transform: translateY(0);
        }

        .btn-success {
            background: var(--success);
        }

        .btn-success:hover {
            box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
        }

        .btn-danger {
            background: var(--danger);
        }

        .btn-danger:hover {
            box-shadow: 0 5px 15px rgba(244, 67, 54, 0.4);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .title {
                font-size: 2.2rem;
            }

            .feature-list {
                grid-template-columns: 1fr;
            }

            .navbar-links {
                display: none;
            }
        }

        /* 动画效果 */
        .fade-enter-active, .fade-leave-active {
            transition: opacity 0.5s ease;
        }
        .fade-enter-from, .fade-leave-to {
            opacity: 0;
        }

        /* 加载动画 */
        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100px;
        }

        .loading-spinner {
            width: 40px;
            height: 40px;
            border: 4px solid rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            border-top-color: var(--neon-purple);
            animation: spin 1s ease-in-out infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        /* 结果显示区域 */
        .result-area {
            background: rgba(30, 30, 30, 0.7);
            padding: 1rem;
            border-radius: 8px;
            margin-top: 1rem;
            min-height: 50px;
            transition: all 0.3s ease;
        }
    </style>
</head>
<body>
    <!-- Vue 应用 -->
    <div id="app">
        <!-- 导航栏 -->
        <nav class="navbar">
            <a href="#" class="navbar-brand">
                <i class="ri-typhoon-fill"></i> Best Image API
            </a>
            <div class="navbar-links">
                <a href="#features" class="navbar-link">功能特性</a>
                <a href="#deployment" class="navbar-link">快速部署</a>
                <a href="#test" class="navbar-link">API测试</a>
                <a href="/admin" class="navbar-link">管理后台</a>
            </div>
        </nav>

        <!-- 粒子背景 -->
        <canvas id="particles"></canvas>

        <div class="container">
            <h1 class="title animate__animated animate__fadeIn">🚀 Best Image API 文档</h1>
            
            <!-- 基本调用卡片 -->
            <div class="card animate__animated animate__fadeInUp">
                <h2 id="basic">基本调用</h2>
                
                <div class="code-copy" id="api-url-container">
                  <pre><code id="api-url">{{ apiUrl }}</code></pre>
                    <button class="copy-btn" @click="copyText(apiUrl)">
                        <i class="ri-file-copy-line"></i> 复制
                    </button>
                </div>
                
                <div class="code-copy" id="pc-url-container">
                  <pre><code id="pc-url">{{ pcUrl }}</code></pre>
                    <button class="copy-btn" @click="copyText(pcUrl)">
                        <i class="ri-file-copy-line"></i> 复制
                    </button>
                </div>
                
                <div class="code-copy" id="pe-url-container">
                  <pre><code id="pe-url">{{ peUrl }}</code></pre>
                    <button class="copy-btn" @click="copyText(peUrl)">
                        <i class="ri-file-copy-line"></i> 复制
                    </button>
                </div>
            </div>
      
            <!-- 功能特性卡片 -->
            <div class="card animate__animated animate__fadeInUp" id="features">
                <h2>功能特性</h2>
                <ul class="feature-list">
                    <li class="feature-item" v-for="feature in features">
                        <i :class="feature.icon" class="feature-icon"></i>
                        <span>{{ feature.text }}</span>
                    </li>
                </ul>
                
              
            </div>

            <!-- 返回测试卡片 -->
            <div class="card animate__animated animate__fadeInUp" id="test">
                <h2>返回测试</h2>
                
                <div class="code-copy" style="max-width: 100%; overflow: hidden;">
                    <img :src="apiTestUrl" style="max-width: 100%; height: auto; display: block;" v-if="apiTestUrl">
                    <div class="loading" v-else>
                        <div class="loading-spinner"></div>
                    </div>
                </div>
            </div>
                 
            <!-- 版本信息卡片 -->
            <div class="card animate__animated animate__fadeInUp">
                <h2>版本号：2.0</h2>
                
                <div class="feature-list">
                    <div class="feature-item" v-for="(feature, index) in versionFeatures">
                        <span>{{ index + 1 }}. {{ feature }}</span>
                    </div>
                </div>
            </div>

            <!-- Redis连接测试卡片 -->
            <div class="card animate__animated animate__fadeInUp">
                <h2>Redis连接测试</h2>
                <button class="btn btn-primary" @click="testRedisConnection">
                    <i class="ri-database-2-line"></i> 测试Redis连接
                </button>
                <transition name="fade">
                    <div class="result-area" v-if="redisResult">
                        {{ redisResult }}
                    </div>
                </transition>
                <div class="loading" v-if="redisLoading">
                    <div class="loading-spinner"></div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 初始化粒子效果
        document.addEventListener('DOMContentLoaded', function() {
            particlesJS('particles', {
                particles: {
                    number: { value: 80 },
                    color: { value: '#ffffff' },
                    shape: { type: 'circle' },
                    opacity: {
                        value: 0.5,
                        random: true
                    },
                    size: {
                        value: 3,
                        random: true
                    },
                    move: {
                        enable: true,
                        speed: 2,
                        direction: 'none',
                        random: true,
                        out_mode: 'out'
                    }
                },
                interactivity: {
                    detect_on: 'canvas',
                    events: {
                        onhover: { 
                            enable: true, 
                            mode: 'repulse' 
                        },
                        onclick: {
                            enable: true,
                            mode: 'push'
                        }
                    },
                    modes: {
                        repulse: {
                            distance: 100,
                            duration: 0.4
                        },
                        push: {
                            particles_nb: 4
                        }
                    }
                }
            });
        });

        // Vue 应用
        const { createApp, ref, onMounted } = Vue;

        createApp({
            setup() {
                // 基本URL
                const apiUrl = ref('');
                const pcUrl = ref('');
                const peUrl = ref('');
                const apiTestUrl = ref('');
                const redisResult = ref('');
                const redisLoading = ref(false);

                // 功能特性列表
                const features = [
                    { icon: 'ri-image-edit-line', text: '智能图片格式协商（WebP优先）' },
                    { icon: 'ri-shield-keyhole-line', text: 'IP黑白名单与自动封禁' },
                    { icon: 'ri-speed-up-line', text: '精细化速率限制' },
                    { icon: 'ri-artboard-2-fill', text: '域名防盗链保护' },
                    { icon: 'ri-database-2-line', text: 'Redis加速支持' },
                    { icon: 'ri-file-chart-line', text: '访问日志记录' },
                    { icon: 'ri-server-line', text: 'Nginx缓存支持' },
                    { icon: 'ri-image-2-line', text: 'AVIF图片支持(开发中)' }
                ];

                // 版本特性
                const versionFeatures = [
                    'Nginx缓存支持',
                    'redis支持',
                    'PHP后台支持',
                    '防盗链支持',
                    'IP黑白名单支持',
                    '访问频率限制',
                    '访问日志记录',
                    '图片格式协商',
                    '图片缓存',
                    '图片压缩'
                ];

                // 生成API URL
                function generateApiUrl(endpoint) {
                    const origin = window.location.origin;
                    const pathname = window.location.pathname;
                    const basePath = pathname.replace(/\/[^\/]+$/, '/');
                    return basePath.endsWith('/') 
                        ? `${origin}${basePath}${endpoint}` 
                        : `${origin}${basePath}/${endpoint}`;
                }

                // 复制文本
                function copyText(text) {
                    navigator.clipboard.writeText(text)
                        .then(() => {
                            // 可以添加一个提示动画或通知
                            alert('复制成功!');
                        })
                        .catch(err => {
                            console.error('复制失败:', err);
                            alert('复制失败，请手动复制');
                        });
                }

                // 测试Redis连接
                function testRedisConnection() {
                    redisLoading.value = true;
                    redisResult.value = '';
                    
                    fetch('test_redis.php')
                        .then(response => response.text())
                        .then(data => {
                            redisResult.value = data;
                            redisLoading.value = false;
                        })
                        .catch(error => {
                            redisResult.value = '连接失败: ' + error;
                            redisLoading.value = false;
                        });
                }

                // 获取当前URL的基本部分（不含查询字符串）
                function getCurrentBaseUrl() {
                    const url = window.location.pathname;
                    return url.substring(0, url.lastIndexOf('/') + 1);
                }

                // 组件挂载后初始化
                onMounted(() => {
                    apiUrl.value = generateApiUrl('api.php');
                    pcUrl.value = generateApiUrl('pc.php');
                    peUrl.value = generateApiUrl('pe.php');
                    
                    // 设置API测试URL
                    const baseUrl = getCurrentBaseUrl();
                    apiTestUrl.value = baseUrl + 'api.php';

                    // 为每个卡片添加动画延迟
                    const cards = document.querySelectorAll('.card');
                    cards.forEach((card, index) => {
                        card.style.animationDelay = `${index * 0.1}s`;
                    });
                });

                return {
                    apiUrl,
                    pcUrl,
                    peUrl,
                    apiTestUrl,
                    features,
                    versionFeatures,
                    redisResult,
                    redisLoading,
                    copyText,
                    testRedisConnection
                };
            }
        }).mount('#app');
    </script>
</body>
</html>